<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var house = {
      name: "汤臣一品",
      price: 280,
      phone: 18800000000
    }
    // 添加属性
    // Object.defineProperty(对象，"属性", { 修饰符 })
    // house.address = "东方之珠斜对面"

    Object.defineProperty(house, "address", {
      value: "东方之珠斜对面", //属性值
      writable: false,  //是否能被修改
      configurable: false,//能否被删除
      enumerable: false,//能否被枚举--遍历
    })
    console.log(house)

    // house.address = "迪士尼斜对面";
    delete house.address
    console.log(house)


    for (var key in house) {
      document.write(house[key])
    }

    Object.defineProperty(house, "phone", {
      value: "13888888888",
      writable: false, //能否被修改
      configurable: false, //能否被删除 
      enumerable: false //能否被遍历
    })

    console.log(house)

    house.phone = "19999999999999"
    console.log(house)


    // Object.defineProperty() 有get 和set  get设置属性值 set 拦截赋值操作

    Object.defineProperty(house, "size", {
      get: function () { //设置属性值
        return "130万平"
      },
      set: function (val) { //拦截到赋值操作
        console.log(val)
      },
      configurable: false, //能否被删除
      enumerable: false,//能否被遍历
    })
    //
    console.log(house)
    house.size = "15平";



  </script>
</body>

</html>